package com.mzy.datepackage.M2022.Aug.twsix;

import com.alibaba.fastjson.JSON;
import org.testng.annotations.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author mzy
 * @Date 2022/8/26 9:22
 * @Version 1.0
 */
public class Demo {

    /**
     * 同一个对象没有变更
     * @param args
     */
    public static void main(String[] args) {

    }

    @Test
    public void demo(){
        // 拥有对象并赋值
        GrandFather grandFather = getGrandFather();
        String string = JSON.toJSONString(grandFather, true);
        System.out.println(string);

        // 修改对象里面的熟悉
        List<Faster> fasterList = grandFather.getFasterList();

        for (int i = 0; i < fasterList.size(); i++) {
            for (int i1 = 0; i1 < fasterList.get(0).getSonList().size(); i1++) {
                fasterList.get(0).getSonList().get(0).setAge(20);
            }
        }

        String string1 = JSON.toJSONString(grandFather, true);
        System.out.println("修改后"+ string1);
    }

    public GrandFather getGrandFather(){
        ArrayList<Son> sons = new ArrayList<>();
        Son sonOne = new Son("儿子一",15);
        Son sonTwo = new Son("儿子二",18);
        Son sonThree = new Son("女儿一",18);
        sons.add(sonOne);
        sons.add(sonTwo);
        sons.add(sonThree);
        ArrayList<Faster> fasterArrayList = new ArrayList<>();
        Faster fasterOne = new Faster("爸爸一",40,sons);
        Faster fasterTwo = new Faster("爸爸二",45,sons);
        fasterArrayList.add(fasterOne);
        fasterArrayList.add(fasterTwo);
        GrandFather grandFather = new GrandFather("爸爸",60,fasterArrayList);

        return grandFather;
    }
}
